package com.quwan.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.quwan.app.service.BannerService;
import com.quwan.config.yml.OssConfig;
import com.quwan.constans.CacheKey;
import com.quwan.entity.TBanner;
import com.quwan.mapper.TBannerMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.stream.Collectors;

/**
 * @author quan
 * @date 2021-06-09 14:54
 */

@Service
@CacheConfig(cacheNames = CacheKey.DATA.banner)
@RequiredArgsConstructor
public class BannerServiceImpl implements BannerService {
    private final TBannerMapper bannerMapper;
    private final OssConfig ossConfig;

    @Override
    @Cacheable
    public List<TBanner> getShowIndexBanner() {
        return bannerMapper.selectList(
                new LambdaQueryWrapper<TBanner>()
                        .eq(TBanner::getIsDelete, 0)
        )
                .stream()
                .map(m -> StringUtils.isBlank(m.getImageUrl()) ? m : m.setImageUrl(ossConfig.getHostname()+"/" + m.getImageUrl()))
                .collect(Collectors.toList());

    }


}
